home *** CD-ROM | disk | FTP | other *** search
/ PC-Blue - MS DOS Public Domain Library / PC-Blue MS-DOS Public Domain Library - NYACC.iso / vol194 / kermasm.arc / MSSET.ASM < prev    next >
Encoding:
Assembly Source File  |  1985-11-14  |  42.3 KB  |  1,739 lines

  1. ; Set command module
  2.  
  3. ; edit history:
  4. ;
  5. ; [v2.28]
  6. ; Added set mode line on/off (from Edgar Butt, Univ. of Md.)
  7. ; Decouple handshake and flow control, decouple both from local echo
  8. ; Made set commands check for junk after the command (even though
  9. ;   most of the commands return incorrectly) (from Greg Small, UC Berkeley)
  10. ; Be more cautious about running out of space when defining macros.
  11. ; Skip leading space in macro definitions
  12. ; Print info on macro free space in the show macros command (suggested by
  13. ;     Greg Small, UC Berkeley)
  14. ; Added set autowrap command.
  15. ; JD 14 May 1985
  16.  
  17.     public setcom, status, stat0, baudprt, escprt, prmptr, dodef
  18.     public setcpt, docom, shomac, atoi
  19.     include msdefs.h
  20.  
  21. macmax    equ    20            ; max # of macros
  22.  
  23. datas     segment    public 'datas'
  24.     extrn    comand:byte, flags:byte, trans:byte, cptfcb:byte, takadr:word
  25.     extrn    taklev:byte, inichk:byte, portval:word, curdsk:byte
  26.     extrn    setktab:byte, setkhlp:byte, dtrans:byte
  27.  
  28. kerm    db      'Kermit-MS>$'
  29. crlf    db      cr,lf,'$'
  30. crlfsp    db    cr,lf,' '    ; crlf space
  31.     db    '$'
  32. eqs    db    ' = $'
  33. ermes1    db    cr,lf,'?Too many macros$'
  34. ermes2    db    cr,lf,'?No room in table for macro$'
  35. ermes3  db      cr,lf,'?Not confirmed$'
  36. ermes4    db    cr,lf,'?No room in take stack to expand macro$'
  37. ermes5    db    cr,lf,'?Not implemented$'
  38. erms23    db    cr,lf,'?Null input not allowed$' ;[jd] 
  39. erms24    db    cr,lf,'?Capture file already open (use close command)$' ;[jd]
  40. erms25    db    cr,lf,'?Input must be numeric$' 
  41. filhlp    db    ' Input file specification for session logging$'
  42. macmsg    db    ' Specify macro name followed by body of macro $'
  43. shmmsg    db    ' Confirm with carriage return $'
  44. prmmsg    db    ' Enter new prompt string $'
  45. sk1msg    db    ' Decimal scan code for key $'
  46. sk2msg    db    ' Redefinition string for key $'
  47. prterr    db    '?Unrecognized value$'
  48. unrec    db    'Baud rate is unknown$'
  49. defpmp    db    'Definition string: $'
  50. esctl    db    'Control-$'         ; [6]
  51. nonmsg    db    'none$'
  52. delmsg    db    'delete$'
  53. onmsg    db    'On'
  54. offmsg    db    'Off'
  55. tmp    db    ?,'$'
  56. sum    db    0
  57. min    db    0
  58. max    db    0
  59. desta    dw    0
  60. numerr    dw    0
  61. numhlp    dw    0
  62. stflg    db    0        ; Says if setting SEND or RECEIVE parameter.
  63. srtmp    db    0
  64. savsp    dw    0
  65. temp    dw    0
  66. temp1   dw      ?               ; Temporary storage.
  67. temp2   dw      ?               ; Temporary storage.
  68.  
  69. modst    db    'Mode line $'
  70. wrpst    db    'Auto wrap $'
  71. locst   db      'Local echo $'
  72. belon    db    'Ring bell after transfer$'
  73. beloff    db    'No bell after transfer$'
  74. vtemst  db    'HEATH-19 emulation $'
  75. cm1st    db    'Communications port: 1$'
  76. cm2st    db    'Communications port: 2$'
  77. capmsg    db    'Session logging $'
  78. eofmsg    db    'EOF mode: $'
  79. flost    db    'No flow control used$'
  80. floxmsg    db    'Flow control: XON/XOFF $'
  81. handst    db    'Handshake used: $'
  82. destst    db    'File destination: $'
  83. diskst    db    'Default disk: $'
  84. blokst    db    'Block check used: $'
  85. ebyst    db    '8-bit quoting done only on request$'
  86. ebvst    db    '8-bit quoting will be done with: $'
  87. sqcst    db    'Send cntrl char prefix: $'
  88. rqcst    db    'Receive cntrl char prefix: $'
  89. debon    db    'Debug mode $'
  90. flwon    db    'Warning $'
  91. parmsg    db    'Parity $'
  92. abfdst    db    'Discard incomplete file$'
  93. abfkst    db    'Keep incomplete file$'
  94. eolst    db    'End-of-line character: $'
  95. ssohst    db    'Send start-of-packet char: $'
  96. rsohst    db    'Receive start-of-packet char: $'
  97. stimst    db    'Send timeout (seconds): $'
  98. rtimst    db    'Receive timeout (seconds): $'
  99. spakst    db    'Send packet size: $'
  100. rpakst    db    'Receive packet size: $'
  101. snpdst    db    '# of send pad chars: $'
  102. rnpdst    db    '# of receive pad chars: $'
  103. timmsg    db    'Timer $'
  104. escmes  db      'Escape character: $'
  105. b03st    db    'Baud rate is 300$'
  106. b12st    db    'Baud rate is 1200$'
  107. b18st    db    'Baud rate is 1800$'
  108. b24st    db    'Baud rate is 2400$'
  109. b48st    db    'Baud rate is 4800$'
  110. b96st    db    'Baud rate is 9600$'
  111. b04st    db    'Baud rate is 45.5$'
  112. b05st    db    'Baud rate is 50$'
  113. b07st    db    'Baud rate is 75$'
  114. b11st    db    'Baud rate is 110$'
  115. b13st    db    'Baud rate is 134.5$'
  116. b15st    db    'Baud rate is 150$'
  117. b06st    db    'Baud rate is 600$'
  118. b20st    db    'Baud rate is 2000$'
  119. b19st    db    'Baud rate is 19200$'
  120. b38st    db    'Baud rate is 38400$'
  121.  
  122. eolhlp    db    cr,lf,'Decimal number between 0 and 31$'
  123. eolerr    db    cr,lf,'Illegal end-of-line character$'
  124. timerr    db    cr,lf,'Illegal timeout value$' 
  125. timhlp    db    cr,lf,'Decimal number between 0 and 94$'
  126. soherr    db    cr,lf,'Illegal start-of-packet character$'
  127. quohlp    db    cr,lf,'Decimal number between 33 and 126$'
  128. quoerr    db    cr,lf,'Illegal control character prefix$'
  129. pakerr    db    cr,lf,'Illegal packet length$'
  130. pakhlp    db    cr,lf,'Decimal number between 20 and 94$'
  131. npderr    db    cr,lf,'Illegal number of pad characters$'
  132. npdhlp    db    cr,lf,'Decimal number between 0 and 99$'
  133. paderr    db    cr,lf,'Illegal pad character$'
  134. padhlp    db    cr,lf,'Decimal number between 0 and 31 or 127$'
  135. eschlp  db      cr,lf,'Enter literal value (ex: Cntrl ])  $'
  136. desterr    db    cr,lf,'Illegal destination device$'
  137. dskhlp    db    cr,lf,'Default disk drive to use, such as A:$'
  138. dskerr    db    cr,lf,'Invalid drive specification$' 
  139.  
  140. sethlp    db    cr,lf
  141.     db    'AUTOWRAP on│off       '
  142.     db      'BAUD rate             '    
  143.     db    cr,lf
  144.     db    'BELL                  '
  145.     db    'BLOCK-CHECK-TYPE      '
  146.     db    cr,lf
  147.     db    'DEBUG                 '
  148.     db    'DEFAULT-DISK          '
  149.     db    cr,lf
  150.     db    'DESTINATION           '
  151.     db    'END-OF-LINE character '
  152.     db    cr,lf
  153.     db    'EOF CTRL-Z│NOCTRL-Z   '
  154.     db      'ESCAPE character      '
  155.     db    cr,lf
  156.     db    'FLOW-CONTROL          '
  157.     db    'HANDSHAKE             '
  158.     db    cr,lf
  159.         db      'HEATH19-EMULATION     '
  160.     db    'INCOMPLETE file       '
  161.     db    cr,lf
  162.     db    'KEY                   ' 
  163.         db      'LOCAL-ECHO            '
  164.     db    cr,lf
  165.     db    'MODE-LINE on│off      '
  166.     db    'PARITY type           '
  167.     db    cr,lf
  168.     db    'PORT for i/o          '
  169.     db    'PROMPT                '
  170.     db    cr,lf
  171.     db    'RECEIVE parameter     '
  172.     db    'REMOTE on/off         '
  173.     db    cr,lf
  174.     db    'SEND parameter        '
  175.     db    'TAKE-ECHO             ' 
  176.     db    cr,lf
  177.     db    'TIMER                 '
  178.         db      'WARNING               '
  179.     db    '$'
  180.  
  181. settab  db      27
  182.     mkeyw    'AUTOWRAP',autost
  183.     mkeyw    'BAUD',baudst
  184.     mkeyw    'BELL',bellst
  185.     mkeyw    'BLOCK-CHECK-TYPE',blkset
  186.     mkeyw    'DEBUG',debst
  187.     mkeyw    'DEFAULT-DISK',dskset
  188.     mkeyw    'DESTINATION',desset
  189.     mkeyw    'END-OF-LINE',eolset
  190.     mkeyw    'EOF',seteof
  191.     mkeyw    'ESCAPE',escape
  192.     mkeyw    'FLOW-CONTROL',floset
  193.     mkeyw    'HANDSHAKE',hndset
  194.     mkeyw    'HEATH19-EMULATION',vts
  195.     mkeyw    'INCOMPLETE',abfset
  196.     mkeyw    'KEY',setkey
  197.     mkeyw    'LOCAL-ECHO',lcal
  198.     mkeyw    'MODE-LINE',modl
  199.     mkeyw    'PARITY',setpar
  200.     mkeyw    'PORT',coms
  201.     mkeyw    'PROMPT',promset
  202.     mkeyw    'RECEIVE',recset
  203.     mkeyw    'REMOTE',remset
  204.     mkeyw    'SEND',sendset
  205.     mkeyw    'SPEED',baudst
  206.     mkeyw    'TAKE-ECHO',takset
  207.     mkeyw    'TIMER',timset
  208.     mkeyw    'WARNING',filwar
  209.  
  210.  
  211. seoftab    db    2
  212.     mkeyw    'CTRL-Z',1
  213.     mkeyw    'NOCTRL-Z',0
  214.  
  215. stsrtb    db    06        ; Number of options.
  216.     mkeyw    'PACKET-LENGTH',srpack
  217.     mkeyw    'PADCHAR',srpad
  218.     mkeyw    'PADDING',srnpd
  219.     mkeyw    'QUOTE',srquo
  220.     mkeyw    'START-OF-PACKET',srsoh
  221.     mkeyw    'TIMEOUT',srtim
  222.  
  223. ontab   db      02H             ; Two entries.
  224.     mkeyw    'OFF',00H
  225.     mkeyw    'ON',01H
  226.  
  227. destab    db    03H        ; Three choices. [27c]
  228.     mkeyw    'DISK',01H
  229.     mkeyw    'PRINTER',00H
  230.     mkeyw    'SCREEN',02H
  231.  
  232. ; What type of block check to use.
  233. blktab    db    03H
  234.     mkeyw    '1-CHARACTER-CHECKSUM',1
  235.     mkeyw    '2-CHARACTER-CHECKSUM',2
  236.     mkeyw    '3-CHARACTER-CRC-CCITT',3
  237.  
  238. ; If abort when receiving files, can keep what we have or discard. [20d]
  239.  
  240. abftab    db    02H        ; Only two options. 
  241.     mkeyw    'DISCARD',01H
  242.     mkeyw    'KEEP',00H
  243.  
  244. partab    db    05H        ; Five entries.            [10 start]
  245.     mkeyw    'EVEN',PAREVN
  246.     mkeyw    'MARK',PARMRK
  247.     mkeyw    'NONE',PARNON
  248.     mkeyw    'ODD',PARODD
  249.     mkeyw    'SPACE',PARSPC
  250.  
  251. flotab    db    2
  252.     mkeyw    'NONE',flonon
  253.     mkeyw    'XON/XOFF',floxon
  254.  
  255. hndtab    db    7
  256.     mkeyw    'BELL',bell
  257.     mkeyw    'CR',cr
  258.     mkeyw    'ESC',esc
  259.     mkeyw    'LF',lf
  260.     mkeyw    'NONE',0
  261.     mkeyw    'XOFF',xoff
  262.     mkeyw    'XON',xon
  263.  
  264. BStab    db    02H            ;Two entries [19c start]
  265.     mkeyw    'BACKSPACE',00H
  266.     mkeyw    'DELETE',01H
  267.  
  268. bdtab    db    010H        ; 16 entries
  269.     mkeyw    '110',b0110
  270.     mkeyw    '1200',b1200
  271.     mkeyw    '134.5',b01345
  272.     mkeyw    '150',b0150
  273.     mkeyw    '1800',b1800
  274.     mkeyw    '19200',b19200
  275.     mkeyw    '2000',b2000
  276.     mkeyw    '2400',b2400
  277.     mkeyw    '300',b0300
  278.     mkeyw    '38400',b38400
  279.     mkeyw    '45.5',b00455
  280.     mkeyw    '4800',b4800
  281.     mkeyw    '50',b0050
  282.     mkeyw    '600',b0600
  283.     mkeyw    '75',b0075
  284.     mkeyw    '9600',b9600
  285.  
  286. ten    dw    10            ; multiplier for setatoi
  287. rdbuf    db    80H DUP(?)
  288. prm    db    30 dup(0)        ; Buffer for new prompt.
  289. prmptr    dw    kerm            ; pointer to prompt
  290. defkw    db    256 dup (?)        ; room for macro name and body
  291. macnum    dw    0            ; one macro yet
  292. mactab    dw    ibmmac            ; default ibm mac is macro 0
  293.     dw    macmax dup (?)        ; empty macro table
  294. defptr    dw    macbuf
  295. macbuf    db    macmax*100 dup (?)    ; buffer for macro defs
  296. macbend    label    byte            ; marker for end of macro buffer
  297. rmlft    db    macmax*10        ; space left in set table
  298. mcctab    db    1            ; macro name table, one initially
  299.     mkeyw    'IBM',0            ; macro # 0
  300.     db    macmax*10 dup (?)    ; room for rest of macro names
  301. shom9a    db    cr,lf,'Free space:  name entries $'
  302. shom9b    db    ', name characters $'
  303. shom9c    db    ', body characters $'
  304.  
  305. ibmmac    db    imlen-1
  306.     db    'set timer on',cr,'set parity mark',cr
  307.     db    'set local-echo on',cr,'set handshake xon',cr
  308.     db    'set flow none',cr
  309. imlen    equ    $-ibmmac
  310.  
  311. ; structure for status information
  312. stent    struc
  313. sttyp    dw    ?        ; type (actually routine to call)
  314. msg    dw    ?        ; message to print
  315. val2    dw    ?        ; needed value: another message, or tbl addr
  316. tstcel    dw    ?        ; address of cell to test, in data segment
  317. basval    dw    0        ; base value, if non-zero
  318. stent    ends
  319.  
  320. sttab    stent    <onoff,vtemst,,flags.vtflg>
  321.     stent    <onoff,locst,,ecoflg,portval>
  322.     stent    <onoff,modst,,flags.modflg>
  323.     stent    <onoff,wrpst,,flags.wrpflg>
  324.     stent    <baudprt>
  325.     stent    <srchkw,parmsg,partab,parflg,portval>
  326.     stent    <onechr,escmes,,trans.escchr>
  327.     stent    <onoff,capmsg,,flags.capflg>
  328.     stent    <msg2,flost,floxmsg,floflg,portval>
  329.     stent    <prhnd>
  330.     stent    <srchkw,destst,destab,flags.destflg>
  331.     stent    <drnum,diskst,,curdsk>
  332.     stent    <onoff,flwon,,flags.flwflg>
  333.     stent    <msg2,beloff,belon,flags.belflg>
  334.     stent    <msg2,abfkst,abfdst,flags.abfflg>
  335.     stent    <srchkw,eofmsg,seoftab,flags.eofcz>
  336.     stent    <onechr,sqcst,,trans.rquote>
  337.     stent    <onechr,rqcst,,dtrans.squote>
  338.     stent    <onechr,rsohst,,trans.rsoh>
  339.     stent    <onechr,ssohst,,trans.ssoh>
  340.     stent    <stnum,rtimst,,trans.rtime>
  341.     stent    <stnum,stimst,,dtrans.stime>
  342.     stent    <stnum,rpakst,,trans.rpsiz>
  343.     stent    <stnum,spakst,,trans.spsiz>
  344.     stent    <stnum,snpdst,,dtrans.spad>
  345.     stent    <stnum,rnpdst,,trans.rpad>
  346.     stent    <onoff,timmsg,,flags.timflg>
  347.     stent    <pr8bit>
  348.     stent    <onechr,eolst,,dtrans.seol>
  349.     stent    <srchkw,blokst,blktab,trans.chklen>
  350.     stent    <msg2,cm2st,cm1st,flags.comflg>
  351.     stent    <onoff,debon,,flags.debug>
  352.     dw    0        ; end of table
  353. sttbuf    db    2000 dup (?)    ; big buffer for status msg.
  354. datas    ends
  355.  
  356. code    segment    public
  357.     extrn cmcfrm:near, prserr:near, comnd:near, dobaud:near
  358.     extrn cmgtch:near, repars:near, coms:near, vts:near, defkey:near
  359.     extrn inicpt:near, prompt:near, nout:near, prtscr:near
  360.     extrn prkey:near, getbaud:near
  361.     assume    cs:code,ds:datas
  362.  
  363. ; This is the SET command.
  364.  
  365. SETCOM  PROC    NEAR
  366.         mov dx,offset settab    ; Parse a keyword from the set table.
  367.         mov bx,offset sethlp
  368.         mov ah,cmkey
  369.         call comnd
  370.          jmp r
  371.         call bx
  372.      jmp setco2
  373.      nop
  374. setco1:    jmp rskp
  375. setco2:    cmp comand.cmstat,cmcfm    ; did they parse a confirm at the end?
  376.     je setco1
  377.     ret
  378. SETCOM    endp
  379.  
  380. docom    proc    near
  381.     mov    dx,offset mcctab
  382.     mov    bx,0
  383.     mov    ah,cmkey
  384.     call    comnd
  385.      jmp    r
  386.     push    bx
  387.     mov    ah,cmcfm
  388.     call    comnd
  389.      pop    bx
  390.      ret
  391.      nop
  392.     pop    bx
  393.     cmp    taklev,maxtak        ; room in take level?
  394.     jl    docom2            ; yes, continue
  395.     mov    dx,offset ermes4    ; else complain
  396.     jmp    reterr
  397. docom2:    inc    taklev            ; increment take level (overflow)
  398.     add    takadr,size takinfo
  399.     shl    bx,1
  400.     mov    si,mactab[bx]        ; point to macro
  401.     mov    cl,[si]            ; get size from macro
  402.     mov    ch,0
  403.     inc    si            ; point to actual definition
  404.     mov    bx,takadr        ; point to current buffer
  405.     mov    [bx].takfcb,0ffh    ; flag as a macro
  406.     mov    [bx].takptr,si        ; point to beginning of def
  407.     mov    [bx].takchl,cl        ; # of chars left in buffer
  408.     mov    [bx].takcnt,cx        ; and in definition
  409.     mov    word ptr [bx].takcnt+2,0 ; zero high order...
  410.     jmp    rskp
  411. docom    endp
  412.  
  413. ; the define command
  414. dodef    proc    near
  415.     cmp    macnum,macmax        ; get current macro count
  416.     jl    dode1            ; no, go on
  417.     mov    dx,offset ermes1    ; else complain
  418.     jmp    reterr            ; and return
  419.  
  420. dode1:    mov    ah,cmtxt
  421.     mov    bx,offset defkw+1    ; buffer for keyword
  422.     mov    dx,offset macmsg
  423.     call    comnd
  424.      ret
  425.      nop
  426.      nop
  427.     cmp    ah,0
  428.     jne    dode2
  429.     ret
  430. dode1a:    mov    dx,offset erms23    ; null input not allowed
  431.     jmp    reterr
  432.  
  433. dode2:    mov    bx,ds            ; address data segment
  434.     mov    es,bx
  435.     cld                ; strings go forward
  436.     mov    cl,ah
  437.     mov    ch,0            ; length
  438.     mov    di,offset defkw+1    ; pointer to keyword
  439.     mov    ah,0            ; # of chars in keyword
  440.     jcxz    dode1a            ; empty keyword, complain
  441.     mov    al,' '
  442.     repe    scasb            ; skip leading blanks
  443.     je    dode1a            ; all blanks, 
  444.     lea    si,[di-1]        ; back up to non-blank
  445.     inc    cx            ; going to look at it again...
  446. ; uppercase keyword, look for end
  447. dode3:    lodsb                ; get a byte
  448.     cmp    al,'a'
  449.     jb    dode4
  450.     cmp    al,'z'
  451.     ja    dode4
  452.     sub    al,'a'-'A'
  453.     mov    [si-1],al        ; uppercase if necessary
  454. dode4:    inc    ah            ; increment word count
  455.     cmp    al,' '            ; is it the break character?
  456.     loopne    dode3            ; no, loop thru rest of word
  457. dode5:    jne    dode6            ; ended with break char?
  458.     dec    ah            ; yes, don't count in length
  459. dode6:    mov    defkw,ah        ; store length in front of it
  460.     add    ah,4            ; add keyword overhead length
  461.     cmp    ah,rmlft        ; will it fit in buffer?
  462.     jb    dode7            ; yes, keep going
  463.  
  464.     mov    dx,offset ermes2    ; else complain
  465.     jmp    reterr
  466.  
  467. dode7:    mov    bx,defptr        ; free def space
  468.     add    bx,cx            ; add length of new def'n
  469.     cmp    bx,offset macbend    ; past end?
  470.     jb    dode7a            ; no, ok to add it
  471.     mov    dx,offset ermes2
  472.     jmp    reterr            ; won't fit, complain
  473.  
  474. dode7a:    sub    rmlft,ah        ; subtract space used in tbl
  475.     mov    di,defptr        ; pointer to free space
  476.     inc    macnum            ; count the macro
  477.     mov    bx,macnum
  478.     shl    bx,1            ; double for word idx!!!
  479.     mov    mactab[bx],di        ; install into table
  480.     mov    [di],cl            ; store length
  481.     inc    di
  482.     jcxz    dode10            ; no copy if 0 length
  483.  
  484. ; copy definition into buffer, changing commas to crs
  485. dode8:    lodsb                ; get a byte
  486.     cmp    al,','            ; comma?
  487.     jne    dode9            ; no, keep going
  488.     mov    al,cr            ; else replace with cr
  489. dode9:    stosb
  490.     loop    dode8            ; keep copying
  491.  
  492. dode10:    mov    defptr,di        ; update free ptr
  493.     mov    bl,defkw
  494.     mov    bh,0
  495.     lea    di,defkw+1[bx]        ; end of keyword
  496.     mov    al,'$'
  497.     stosb
  498.     mov    ax,macnum
  499.     stosb                ; low-order
  500.     mov    al,0            ; high-order is always 0.
  501.     stosb
  502.  
  503. ; now install into table
  504.     mov    bx,offset mcctab
  505.     mov    dx,offset defkw
  506.     call    addtab
  507.     jmp    rskp
  508. dodef    endp
  509.  
  510. ; add an entry to a keyword table
  511. ; enter with bx/ table address, dx/ ptr to new entry
  512. ; no check is made to see if the entry fits in the table.
  513. addtab    PROC    NEAR
  514.     push    es
  515.     cld
  516.     mov    ax,ds
  517.     mov    es,ax        ; address data segment
  518.     mov    bp,bx        ; remember where tbl starts
  519.     mov    cl,[bx]        ; pick up length of table
  520.     mov    ch,0
  521.     inc    bx        ; point to actual table...
  522. addta1:    push    cx        ; preserve count
  523.     mov    si,dx        ; point to entry
  524.     lodsb            ; get length of new entry
  525.     mov    cl,[bx]        ; and length of table entry...
  526.     mov    ah,0        ; assume they're the same size
  527.     cmp    al,cl        ; are they the same?
  528.     lahf            ; remember result of comparison...
  529.     jae    addta2        ; is new smaller? no, use table length
  530.     mov    cl,al        ; else use length of new entry
  531. addta2:    mov    ch,0
  532.     lea    di,[bx+1]    ; point to actual keyword
  533.     repe    cmpsb        ; compare strings
  534.     pop    cx        ; restore count
  535.     jb    addta4        ; below, insert before this one
  536.     jne    addta3        ; not below or same, keep going
  537.     sahf            ; same. get back result of length comparison
  538.     jb    addta4        ; if new len is smaller, insert here
  539.     jne    addta3        ; if not same size, keep going
  540.     mov    si,bx        ; else this is where entry goes
  541.     jmp    short addta6    ; no insertion required...
  542. addta3:    mov    al,[bx]
  543.     mov    ah,0
  544.     add    bx,ax        ; skip this entry
  545.     add    bx,4        ; len + $ + value...
  546.     loop    addta1        ; and keep looking
  547. addta4:    mov    si,bx        ; this is first location to move
  548.     mov    di,bx
  549.     inc    ds:byte ptr [bp] ; remember we're adding one...
  550.     jcxz    addta6        ; no more entries, forget this stuff
  551.     mov    bh,0        ; this stays 0
  552. addta5:    mov    bl,[di]        ; get length
  553.     lea    di,[bx+di+4]    ; end is origin + length + 4 for len, $, value
  554.     loop    addta5        ; loop thru remaining keywords
  555.     mov    cx,di
  556.     sub    cx,si        ; compute # of bytes to move
  557.     push    si        ; preserve loc for new entry
  558.     mov    si,di        ; first to move is last
  559.     dec    si        ; minus one
  560.     mov    di,dx        ; new entry
  561.     mov    bl,[di]        ; get length
  562.     lea    di,[bx+si+4]    ; dest is source + length of new + 4
  563.     std            ; move backwards
  564.     rep    movsb        ; move the table down
  565.     cld            ; put flag back
  566.     pop    si
  567. addta6:    mov    di,si        ; this is where new entry goes
  568.     mov    si,dx        ; this is where it comes from
  569.     mov    cl,[si]        ; length
  570.     mov    ch,0
  571.     add    cx,4        ; overhead bytes
  572.     rep    movsb        ; stick it in
  573.     pop    es
  574.     ret            ; and return
  575. addtab    endp
  576.  
  577. ; Show defined macros.
  578. SHOMAC    PROC    NEAR
  579.     mov ah,cmtxt
  580.     mov bx,offset rdbuf
  581.     mov dx,offset shmmsg
  582.     call comnd
  583.      jmp r 
  584.     cmp ah,0        ; Bare CR means show all macros.
  585.     jne shom2        ; No, he wants specific macro expanded.
  586.     mov si,offset mcctab    ; Table of macro names.
  587.     lodsb
  588.     mov cl,al        ; Number of macro entries.
  589.     mov ch,0
  590. shom0:    jcxz shom1        ; Done if none left to display.
  591.     lodsb            ; Length of macro name.
  592.     push ax            ; Don't forget it.
  593.     mov ah,prstr
  594.     mov dx,offset crlfsp    ; Go to new line.
  595.     int dos
  596.     mov dx,si        ; Print macro name.
  597.     int dos
  598.     mov dx,offset eqs
  599.     int dos
  600.     pop ax
  601.     mov ah,0
  602.     add si,ax        ; Skip over name.
  603.     inc si            ; Get to macro number.
  604.     mov bx,[si]        ; Pick it up.
  605.     call expmac        ; Expand the macro.
  606.     dec cx
  607.     add si,2        ; Skip over macro number.
  608.     jmp shom0        ; And do the rest.
  609. shom1:    mov ah,prstr
  610.     mov dx,offset shom9a    ; free space: name entries
  611.     int dos
  612.     mov ax,macmax
  613.     sub ax,macnum        ; compute # of free name entries
  614.     call nout
  615.     mov ah,prstr
  616.     mov dx,offset shom9b    ; name characters
  617.     int dos
  618.     mov al,rmlft
  619.     mov ah,0
  620.     call nout
  621.     mov ah,prstr
  622.     mov dx,offset shom9c    ; body characters
  623.     int dos
  624.     mov ax,offset macbend
  625.     sub ax,defptr
  626.     call nout
  627.     mov ah,prstr
  628.     mov dx,offset crlf
  629.     int dos
  630.     jmp rskp
  631. shom2:    mov ah,prstr
  632.     mov dx,offset ermes3
  633.     int dos
  634.     jmp rskp
  635. SHOMAC    ENDP
  636.  
  637. ; Expand the macro, called with BX/macro number.
  638. expmac:    push si
  639.     push cx
  640.     mov si,offset mactab    ; Table of address expansions.
  641.     shl bx,1        ; Double and use as index into table.
  642.     mov si,[si+bx]        ; Get address of expansion in question.
  643.     mov ax,si        ; Address of string.
  644.     inc ax            ; Don't print length.
  645.     mov cl,[si]        ; Length of string.
  646.     mov ch,0
  647.     call prkey        ; Print it.
  648.     pop cx
  649.     pop si
  650.     ret
  651.  
  652. seteof    proc    near
  653.     mov ah,cmkey
  654.     mov bx,0
  655.     mov dx,offset seoftab
  656.     call comnd
  657.      jmp r
  658.     push bx
  659.     mov ah,cmcfm
  660.     call comnd
  661.      jmp seteo1        ; error return...
  662.      nop
  663.     pop bx
  664.     mov flags.eofcz,bl    ; set value
  665.     jmp rskp        ; and return
  666. seteo1:    pop bx
  667.     ret
  668. seteof    endp
  669.  
  670. ;       This is the ESCAPE character SET subcommand.     [6 start]
  671.  
  672. ESCAPE  PROC    NEAR
  673.     call cmgtch        ; Get a char.
  674.     cmp ah,0
  675.     jns es1            ; Terminator or no?
  676.     and ah,7FH        ; Turn off minus bit.
  677.     cmp ah,'?'
  678.     jne es0
  679.     mov dx,offset eschlp
  680.     mov ah,prstr
  681.     int dos
  682.     mov dx,offset crlf
  683.     int dos
  684.     mov dx,comand.cmprmp
  685.     int dos
  686.     mov bx,comand.cmdptr
  687.     mov al,'$'
  688.     mov [bx],al
  689.     mov dx,offset comand.cmdbuf
  690.     int dos
  691.     dec comand.cmcptr        ; Ignore dollar sign.
  692.     dec comand.cmccnt
  693.     mov comand.cmaflg,0
  694.     jmp repars
  695. es0:    mov ah,prstr
  696.     mov dx,offset ermes3
  697.     int dos
  698.     ret
  699. es1:      mov temp,ax
  700.     mov ah,cmcfm
  701.     call comnd
  702.      jmp es0
  703.      nop            ; Take up 3 bytes.
  704.     mov ax,temp
  705.     mov trans.escchr,ah    ; Save new value.
  706.     ret
  707. ESCAPE  ENDP            ; [6 end]
  708.  
  709. ;     This is the End-of-line character SET subcommand.
  710.  
  711. EOLSET    PROC    NEAR
  712.     mov min,0
  713.     mov max,1FH
  714.     mov sum,0
  715.     mov tmp,10
  716.     mov temp1,0
  717.     mov desta,offset dtrans.seol
  718.     mov numhlp,offset eolhlp
  719.     mov numerr,offset eolerr
  720.     jmp num0        ; Common routine for parsing numerical input.
  721. EOLSET    ENDP
  722.  
  723. num0:    call cmgtch        ; Get the first char into AH.
  724.     cmp ah,0
  725.     js num1
  726.     cmp ah,'0'
  727.     jl num1
  728.     cmp ah,'9'
  729.     ja num1
  730.     mov temp1,1
  731.     sub ah,30H
  732.     mov dl,ah
  733.     mov al,sum
  734.     mul tmp
  735.     add al,dl
  736.     mov sum,al
  737.     jmp num0
  738. num1:    and ah,7FH
  739.     cmp ah,CR
  740.     jne num2
  741.     cmp temp1,0
  742.     je num21
  743.     mov al,sum
  744.     cmp al,min
  745.     jl num3
  746.     cmp al,max
  747.     jg num3
  748.     mov bx,desta
  749.     mov [bx],al
  750.     ret
  751. num2:    cmp ah,03FH        ; Question mark?
  752.     je num4
  753. num21:    mov ah,prstr
  754.     mov dx,offset ermes3
  755.     int dos
  756.     jmp prserr
  757. num3:    mov ah,prstr
  758.     mov dx,numerr
  759.     int dos
  760.     jmp prserr
  761. num4:    mov ah,prstr
  762.     mov dx,numhlp
  763.     int dos
  764.     mov dx,offset crlf
  765.     int dos
  766.     mov dx,comand.cmprmp
  767.     int dos
  768.     mov bx,comand.cmdptr
  769.     mov al,'$'
  770.     mov [bx],al
  771.     mov dx,offset comand.cmdbuf
  772.     int dos
  773.     dec comand.cmcptr        ; Don't count the dollar sign.
  774.     dec comand.cmccnt        ; Or the question mark.
  775.     mov comand.cmaflg,0        ; Check for more input.
  776.     jmp repars
  777.  
  778. ;       This is the LOCAL echo SET subcommand.
  779.  
  780. LCAL    PROC    NEAR
  781.         mov dx,offset ontab
  782.         mov bx,0
  783.         mov ah,cmkey
  784.         call comnd
  785.          jmp r
  786.         push bx                 ; Save the parsed value.
  787.         mov ah,cmcfm
  788.         call comnd              ; Get a confirm.
  789.          jmp lcl0        ;  Didn't get a confirm.
  790.      nop
  791.         pop bx
  792.     mov si,portval
  793.         mov [si].ecoflg,bl     ; Set the local echo flag.
  794.     ret
  795. lcl0:    pop bx
  796.     ret
  797. LCAL    ENDP
  798.  
  799. ;    SET mode line on or off
  800. MODL    PROC    NEAR
  801.     mov    dx,offset ontab        ; parse an on or off
  802.     mov    bx,0            ; no special help...
  803.     mov    ah,cmkey
  804.     call    comnd
  805.      jmp    r
  806.     push    bx            ; save value
  807.     mov    ah,cmcfm
  808.     call    comnd
  809.      pop    bx            ; isn't this horrible?
  810.      ret
  811.      nop
  812.     pop    bx
  813.     mov    flags.modflg,bl        ; set flag appropriately
  814.     jmp    rskp            ; and return
  815. MODL    ENDP
  816.  
  817. FILWAR  PROC    NEAR
  818.         mov dx,offset ontab
  819.         mov bx,0
  820.         mov ah,cmkey
  821.         call comnd
  822.          jmp r
  823.         push bx
  824.         mov ah,cmcfm
  825.         call comnd              ; Get a confirm.
  826.          jmp fil0        ; Didn't get a confirm.
  827.      nop
  828.         pop bx
  829.         mov flags.flwflg,bl     ; Set the filewarning flag.
  830.     ret
  831. fil0:    pop bx
  832.     ret
  833. FILWAR  ENDP
  834.  
  835. ;       This is the SET aborted-file command.  [20d]
  836.  
  837. ABFSET  PROC    NEAR
  838.         mov dx,offset abftab
  839.         mov bx,0
  840.         mov ah,cmkey
  841.         call comnd
  842.          jmp r
  843.         push bx
  844.         mov ah,cmcfm
  845.         call comnd              ; Get a confirm.
  846.          jmp abf0        ;  Didn't get a confirm.
  847.      nop
  848.         pop bx
  849.         mov flags.abfflg,bl     ; Set the aborted file flag.
  850.     ret
  851. abf0:    pop bx
  852.     ret
  853. ABFSET  ENDP
  854.  
  855. ;       This is the SET Parity command.                [10 start]
  856.  
  857. SETPAR  PROC    NEAR
  858.         mov dx,offset partab
  859.         mov bx,0
  860.         mov ah,cmkey
  861.         call comnd
  862.          jmp r
  863.         push bx
  864.         mov ah,cmcfm
  865.         call comnd              ; Get a confirm.
  866.          jmp par0        ;  Didn't get a confirm.
  867.      nop
  868.         pop bx
  869.     mov si,portval
  870.         mov [si].parflg,bl    ; Set the parity flag.
  871.     cmp bl,parnon        ; Resetting parity to none? [21b]
  872.     je setp0        ; Yes, reset 8 bit quote character. [21b]
  873.     mov trans.ebquot,dqbin    ; Else, do quoting.  [21b]
  874.     ret            ; That's it.  [21b]
  875. setp0:    mov trans.ebquot,'Y'    ; If none, say will quote upon request. [21b]
  876.     ret
  877. par0:    pop bx
  878.     ret
  879. SETPAR  ENDP                            ; [10 end]
  880.  
  881. ; Sets debugging mode on and off.
  882.  
  883. DEBST    PROC    NEAR
  884.         mov dx,offset ontab
  885.         mov bx,0
  886.         mov ah,cmkey
  887.         call comnd
  888.          jmp r
  889.         push bx
  890.         mov ah,cmcfm
  891.         call comnd              ; Get a confirm.
  892.          jmp deb0        ; Didn't get a confirm.
  893.      nop
  894.         pop bx
  895.         mov flags.debug,bl    ; Set the DEBUG flag.
  896.     ret
  897. deb0:    pop bx
  898.     ret
  899. DEBST   ENDP
  900.  
  901. ; Turn bell on or off.    [17a start]
  902.  
  903. BELLST    PROC    NEAR
  904.     mov dx,offset ontab
  905.     mov bx,0
  906.     mov ah,cmkey
  907.     call comnd
  908.      jmp r
  909.     push bx
  910.     mov ah,cmcfm
  911.     call comnd
  912.      jmp bel0
  913.      nop
  914.     pop bx
  915.     mov flags.belflg,bl
  916.     ret
  917. bel0:    pop bx
  918.     ret
  919. BELLST    ENDP                      ;  [17a end]
  920.  
  921. ; Toggle echo'ing of TAKE file to be either ON or OFF.
  922. TAKSET    PROC    NEAR
  923.     mov dx,offset ontab
  924.     mov bx,0
  925.     mov ah,cmkey
  926.     call comnd
  927.      jmp r
  928.     push bx
  929.     mov ah,cmcfm
  930.     call comnd
  931.      jmp tak0
  932.      nop
  933.     pop bx
  934.     mov flags.takflg,bl
  935.     ret
  936. tak0:    pop bx
  937.     ret
  938. TAKSET    ENDP                      ;  [17a end]
  939.  
  940. ; Set timer ON/OFF during file transfer.
  941. TIMSET    PROC    NEAR
  942.     mov dx,offset ontab
  943.     mov bx,0
  944.     mov ah,cmkey
  945.     call comnd
  946.      jmp r
  947.     push bx
  948.     mov ah,cmcfm
  949.     call comnd
  950.      jmp tim0
  951.      nop
  952.     pop bx
  953.     mov flags.timflg,bl
  954.     ret
  955. tim0:    pop bx
  956.     ret
  957. TIMSET    ENDP                      ;  [17a end]
  958.  
  959. ; Allow user to change the "Kermit-MS>" prompt.
  960. PROMSET    PROC    NEAR
  961.     mov ah,cmtxt
  962.     mov bx,offset prm        ; Read in the prompt.
  963.     mov dx,offset prmmsg
  964.     call comnd
  965.      jmp r
  966.     cmp ah,0            ; Just a bare CR?
  967.     jne prom0
  968.     mov ax,offset kerm
  969.     jmp prom1
  970. prom0:    mov byte ptr [bx],'$'        ; End of string.
  971.     mov ax,offset prm
  972. prom1:    mov prmptr,ax            ; Remember it.
  973.     jmp rskp
  974. PROMSET    ENDP
  975.  
  976. ; Set Flow-Control subcommand.
  977. FLOSET    PROC    NEAR
  978.         mov dx,offset flotab
  979.       xor bx,bx
  980.         mov ah,cmkey
  981.         call comnd
  982.          jmp r
  983.         push bx
  984.         mov ah,cmcfm
  985.         call comnd              ; Get a confirm.
  986.          jmp flox        ; Didn't get a confirm.
  987.      nop
  988.         pop bx
  989.     mov si,portval
  990.     mov [si].flowc,bx    ; Flow control value.
  991.     cmp bx,0        ; Turning it off?
  992.     je flo0            ; Yes.
  993.         mov [si].floflg,1    ; Say we're doing flow control.
  994.     ret
  995. flo0:    mov [si].floflg,bl    ; Say we're not doing flow control.
  996.     ret
  997. flox:    pop bx
  998.     ret
  999. FLOSET    ENDP
  1000.  
  1001. ; Set Handshake subcommand.
  1002. HNDSET    PROC    NEAR
  1003.         mov dx,offset hndtab
  1004.         mov bx,0
  1005.         mov ah,cmkey
  1006.         call comnd
  1007.          jmp r
  1008.         push bx
  1009.         mov ah,cmcfm
  1010.         call comnd              ; Get a confirm.
  1011.          jmp hndx        ; Didn't get a confirm.
  1012.      nop
  1013.         pop bx
  1014.     mov si,portval
  1015.     cmp bl,0        ; Setting handshake off?
  1016.     je hnd0            ; Yes.
  1017.     mov [si].hndflg,1    ; And turn on handshaking.
  1018.     mov [si].hands,bl    ; Use this char as the handshake.
  1019.     ret
  1020. hnd0:    mov [si].hndflg,0    ; No handshaking.
  1021.     ret
  1022. hndx:    pop bx
  1023.     ret
  1024. HNDSET    ENDP
  1025.  
  1026. ; Set block check type sub-command.
  1027. BLKSET    PROC    NEAR
  1028.         mov dx,offset blktab
  1029.         mov bx,0
  1030.         mov ah,cmkey
  1031.         call comnd
  1032.          jmp r
  1033.         push bx
  1034.         mov ah,cmcfm
  1035.         call comnd              ; Get a confirm.
  1036.          jmp blk0        ; Didn't get a confirm.
  1037.      nop
  1038.         pop bx
  1039.     mov trans.chklen,bl    ; Use this char as the handshake.
  1040.     mov inichk,bl        ; Save here too.
  1041.     ret
  1042. blk0:    pop bx
  1043.     ret
  1044. BLKSET    ENDP
  1045.  
  1046. ; Set destination for incoming file.
  1047. DESSET    PROC    NEAR
  1048.         mov dx,offset destab
  1049.         mov bx,0
  1050.         mov ah,cmkey
  1051.         call comnd
  1052.          jmp r
  1053.         push bx
  1054.         mov ah,cmcfm
  1055.         call comnd              ; Get a confirm.
  1056.          jmp des0        ; Didn't get a confirm.
  1057.        nop
  1058.         pop bx
  1059.         mov flags.destflg,bl    ; Set the destination flag.
  1060.     cmp bl,2        ; Is dest the screen? [27c]
  1061.     jne desa        ; No, then done. [27c]
  1062.     mov flags.xflg,1    ; Remember it here. [27c]
  1063.     ret
  1064. desa:    mov flags.xflg,0    ; Don't write to screem [27c]
  1065.     ret
  1066. des0:    pop bx
  1067.     ret
  1068. DESSET    ENDP
  1069.  
  1070. ; Set default disk for sending/receiving, etc.
  1071. DSKSET    PROC    NEAR
  1072.     mov comand.cmcr,1    ; Don't want filename specified.
  1073.     mov ah,cmifi        ; Parse for drive specification.
  1074.     mov dx,offset rdbuf    ; Read into handy buffer.
  1075.     mov bx,offset dskhlp    ; Text of help message.
  1076.     call comnd
  1077.      jmp r
  1078.     mov ah,cmcfm
  1079.     call comnd
  1080.      jmp r
  1081.     cmp flags.nmoflg,0    ; Fail if specified file name.
  1082.     je dsk1
  1083. dsk0:    mov ah,prstr
  1084.     mov dx,offset dskerr    ; Illegal drive specification.
  1085.     int dos
  1086.     ret
  1087. dsk1:    mov bx,offset rdbuf
  1088.     mov ah,[bx]        ; Get the drive they said to use.
  1089.     cmp ah,0        ; Did they type a bare CR?
  1090.     je dsk0            ; Yes, complain.
  1091.     mov curdsk,ah        ; And remember it.
  1092.     dec ah
  1093.     mov dl,ah
  1094.     mov ah,seldsk
  1095.     int dos
  1096.     ret
  1097. DSKSET    ENDP    
  1098.  
  1099. ; set autowrap on or off
  1100. autost    proc    near
  1101.     mov    ah,cmkey
  1102.     mov    dx,offset ontab
  1103.     mov    bx,0            ; use canned help
  1104.     call    comnd
  1105.      ret                ; uh oh
  1106.      nop
  1107.      nop                ; isn't this silly?
  1108.     push    bx            ; save parsed value
  1109.     mov    ah,cmcfm
  1110.     call    comnd
  1111.      pop    bx
  1112.      ret
  1113.      nop                ; fail return
  1114.     pop    bx            ; get return value back
  1115.     mov    flags.wrpflg,bl        ; set flag correctly
  1116.     ret                ; and return
  1117. autost    endp
  1118.  
  1119. ;  This function sets the baud rate.
  1120.  
  1121. BAUDST  PROC    NEAR
  1122.         mov dx,offset bdtab
  1123.         mov bx,0
  1124.         mov ah,cmkey
  1125.         call comnd
  1126.          jmp r
  1127.     push bx
  1128.     mov ah,cmcfm
  1129.     call comnd        ; Get a confirm.
  1130.      jmp bau0        ; Didn't get one.
  1131.       nop
  1132.     pop bx
  1133.     mov si,portval
  1134.     mov ax,[si].baud    ; Remember original value. [25]
  1135.     mov [si].baud,bx    ; Set the baud rate.
  1136.     call dobaud        ; Use common code. [19a] 
  1137.     ret
  1138. bau0:    pop bx
  1139.     ret
  1140. BAUDST  ENDP
  1141.  
  1142. SENDSET    PROC    NEAR
  1143.     mov stflg,'S'        ; Setting SEND parameter 
  1144. sndst0: mov dx,offset stsrtb    ; Parse a keyword.
  1145.         mov bx,0
  1146.         mov ah,cmkey
  1147.         call comnd
  1148.          jmp r
  1149.         call bx
  1150.      nop
  1151.      nop
  1152.      nop
  1153.     jmp rskp
  1154. SENDSET    ENDP
  1155.  
  1156. recset:    mov stflg,'R'        ; Setting RECEIVE paramter.
  1157.     jmp sndst0
  1158.  
  1159. remset    proc    near
  1160.     mov    ah,cmkey
  1161.     mov    dx,offset ontab
  1162.     mov    bx,0
  1163.     call    comnd
  1164.      jmp    r
  1165.     push    bx        ; save parsed value
  1166.     mov    ah,cmcfm
  1167.     call    comnd        ; confirm
  1168.      pop    bx
  1169.      ret            ; return on failure
  1170.      nop
  1171.     pop    bx
  1172.     mov    flags.remflg,bl    ; set remote setting
  1173.     jmp    rskp        ; and return
  1174. remset    endp
  1175.  
  1176. ; Set send/receive start-of-header.
  1177. srsoh:    mov min,0
  1178.     mov max,1FH
  1179.     mov sum,0
  1180.     mov tmp,10
  1181.     mov desta,offset trans.ssoh    ; Assume SEND.
  1182.     cmp stflg,'S'            ; Setting SEND paramter?
  1183.     je srsoh0
  1184.     mov desta,offset trans.rsoh
  1185. srsoh0:    mov numhlp,offset eolhlp    ; Reuse help message.
  1186.     mov numerr,offset soherr
  1187.     mov temp1,0
  1188.     jmp num0        ; Common routine for parsing numerical input.
  1189.  
  1190. ; Set send/receive timeout.
  1191. srtim:    mov min,0
  1192.     mov max,94
  1193.     mov sum,0
  1194.     mov tmp,10
  1195.     mov desta,offset dtrans.stime    ; Assume SEND.
  1196.     cmp stflg,'S'            ; Setting SEND paramter?
  1197.     je srtim0
  1198.     mov desta,offset trans.rtime
  1199. srtim0:    mov numhlp,offset timhlp    ; Reuse help message.
  1200.     mov numerr,offset timerr
  1201.     mov temp1,0
  1202.     jmp num0        ; Common routine for parsing numerical input.
  1203.  
  1204. ; Set send/receive packet length.
  1205. srpack:    mov min,20
  1206.     mov max,94
  1207.     mov sum,0
  1208.     mov tmp,10
  1209.     mov desta,offset trans.spsiz
  1210.     cmp stflg,'S'        ; Setting SEND paramter?
  1211.     je srpak0
  1212.     mov desta,offset trans.rpsiz
  1213. srpak0:    mov numhlp,offset pakhlp
  1214.     mov numerr,offset pakerr
  1215.     mov temp1,0
  1216.     jmp num0        ; Parse numerical input.
  1217.  
  1218. ; Set send/receive number of padding characters.
  1219. srnpd:    mov min,0
  1220.     mov max,99
  1221.     mov sum,0
  1222.     mov tmp,10
  1223.     mov desta,offset dtrans.spad
  1224.     cmp stflg,'S'        ; Setting SEND paramter?
  1225.     je srnpd0
  1226.     mov desta,offset trans.rpad
  1227. srnpd0:    mov numhlp,offset npdhlp
  1228.     mov numerr,offset npderr
  1229.     mov temp1,0
  1230.     jmp num0        ; Parse numerical input.
  1231.  
  1232. ; Set send/receive padding character.
  1233. srpad:    mov min,0
  1234.     mov max,127
  1235.     mov sum,0
  1236.     mov tmp,10
  1237.     mov srtmp,0FFH        ; Haven't seen anything yet.
  1238.     mov desta,offset srtmp
  1239.     mov numhlp,offset padhlp
  1240.     mov numerr,offset paderr
  1241.     mov temp1,0
  1242.     mov savsp,sp
  1243.     call num0        ; Parse numerical input.
  1244.     mov sp,savsp
  1245.     mov temp,offset trans.spadch
  1246.     cmp stflg,'S'
  1247.     je srpad1
  1248.     mov temp,offset trans.rpadch
  1249. srpad1:    mov bx,offset srtmp
  1250.     mov ah,[bx]
  1251.     cmp ah,0FFH        ; Did they end up not doing the command?
  1252.     je srpad3
  1253.     cmp ah,127        ; This is allowed.
  1254.     je srpad2
  1255.     cmp ah,32
  1256.     jb srpad2        ; Between 0 and 31 is OK too.
  1257.     mov ah,prstr
  1258.     mov dx,offset paderr
  1259.     int dos
  1260.     ret
  1261. srpad2:    mov bx,temp        ; Set the real pad char.
  1262.     mov [bx],ah
  1263. srpad3:    ret
  1264.  
  1265. ; Set send/receive control character prefix.
  1266. srquo:    mov min,33
  1267.     mov max,126
  1268.     mov sum,0
  1269.     mov tmp,10
  1270.     mov desta,offset trans.rquote    ; Used for outgoing packets.
  1271.     cmp stflg,'S'            ; Setting outgoing quote char?
  1272.     je srquo0    
  1273.     mov desta,offset dtrans.squote    ; For incoming quote char.
  1274. srquo0:    mov numhlp,offset quohlp
  1275.     mov numerr,offset quoerr
  1276.     mov temp1,0
  1277.     jmp num0            ; Parse numerical input.
  1278.  
  1279. ;       This is the STATUS command.
  1280.  
  1281. STATUS  PROC    NEAR
  1282.         mov ah,cmcfm
  1283.         call comnd              ; Get a confirm.
  1284.          jmp r                  ;  Didn't get a confirm.
  1285.     mov dx,offset crlf
  1286.     mov ah,prstr
  1287.     int dos            ; initial crlf
  1288.         call stat0
  1289.     mov cx,di        ; End of buffer
  1290.     sub cx,ax        ; Get length of buffer.
  1291.     dec cx            ; Account for null.
  1292.     mov di,ax        ; Buffer pointer.
  1293.     call prtscr        ; Put data onto the screen. 
  1294.         jmp rskp
  1295. STATUS    ENDP
  1296.  
  1297. ; Return a pointer to status message in AX, ptr to end in DI.
  1298.  
  1299. STAT0   PROC    NEAR
  1300.     push    es
  1301.     mov    ax,ds
  1302.     mov    es,ax        ; address data segment
  1303.     cld            ; make sure strings go the right way
  1304.     mov    di,offset sttbuf ; point to destination buffer
  1305.     mov    bx,offset sttab    ; table to control printing
  1306.     mov    al,' '        ; start with a space
  1307.     stosb            ; in the buffer
  1308.     mov    ax,0        ; need-new-line flag
  1309. stat01:    cmp    word ptr [bx],0    ; end of table?
  1310.     je    stat02        ; yes, exit routine
  1311.     push    bx
  1312.     push    di        ; remember important values
  1313.     push    ax
  1314.     call    [bx].sttyp    ; call the appropriate routine
  1315.     pop    ax
  1316.     pop    cx        ; return buffer value
  1317.     pop    bx        ; and ptr
  1318.     or    ax,ax        ; do we need a newline?
  1319.     jne    stat03        ; yes, go put one in
  1320.     sub    cx,di        ; else see how many columns they used
  1321.     add    cx,40        ; this is where we'd like to be
  1322. ; if cx is negative here, we have a problem...
  1323.     mov    al,' '
  1324.     rep    stosb        ; add right # of spaces
  1325.     mov    ax,1        ; note we need a newline next time
  1326.     jmp    short stat04    ; and keep looping around
  1327. stat03:    mov    cx,3
  1328.     mov    si,offset crlfsp
  1329.     rep    movsb        ; append crlf to string
  1330.     xor    ax,ax        ; reset newline flag
  1331. stat04:    add    bx,size stent    ; advance to next one
  1332.     jmp    stat01
  1333. stat02:    mov    al,0        ; end buffer
  1334.     stosb
  1335.     mov    ax,offset sttbuf
  1336.     pop    es        ; restore this
  1337.     ret            ; and return
  1338. STAT0    ENDP
  1339.  
  1340. ; handler routines for status
  1341. ; all are called with di/ destination buffer, bx/ stat ptr.  They
  1342. ; can change any register but the segment registers, must update
  1343. ; di to the end of the buffer.
  1344.  
  1345. ; copy the message into the buffer
  1346. stmsg    proc    near
  1347.     mov    si,[bx].msg    ; get message address
  1348. stms1:    lodsb            ; get a byte
  1349.     stosb            ; drop it off
  1350.     cmp    al,'$'        ; end of message?
  1351.     jne    stms1        ; no, keep going
  1352.     dec    di        ; else back up ptr
  1353.     ret            ; and return
  1354. stmsg    endp
  1355.  
  1356. ; get address of test value in stent.  Returns address in si
  1357. stval    proc    near
  1358.     mov    si,[bx].basval    ; get base value
  1359.     cmp    si,0        ; any there?
  1360.     je    stva1        ; no, keep going
  1361.     mov    si,[si]        ; yes, use as base address
  1362. stva1:    add    si,[bx].tstcel    ; add offset of test cell
  1363.     ret            ; and return it
  1364. stval    endp
  1365.  
  1366. ; print a single character
  1367. onechr    proc    near
  1368.     call    stmsg        ; copy message part first
  1369.     call    stval        ; pick up test value address
  1370.     mov    al,[si]        ; this is char to print
  1371.     cmp    al,' '        ; printable?
  1372.     jae    onech1        ; yes, keep going
  1373.     add    al,64        ; make printable.
  1374.     mov    byte ptr [di],'¬'
  1375.     inc    di        ; note ctrl char
  1376. onech1:    stosb            ; drop char off
  1377.     ret            ; and return
  1378. onechr    endp
  1379.  
  1380. ; numeric field...
  1381. stnum    proc    near
  1382.     call    stmsg        ; copy message
  1383.     call    stval        ; pick up value address
  1384.     mov    al,[si]        ; get value
  1385.     mov    ah,0        ; high order is 0
  1386.     call    outnum        ; put number into buffer
  1387.     ret            ; and return
  1388. stnum    endp
  1389.  
  1390. ; translate the number in ax...
  1391. outnum    proc    near
  1392.     cwd
  1393.     mov    bx,10
  1394.     div    bx        ; divide to get digit
  1395.     push    dx        ; save remainder digit
  1396.     or    ax,ax        ; test quotient
  1397.     jz    outnu1        ; zero, no more of number
  1398.     call    outnum        ; else call for rest of number
  1399. outnu1:    pop    ax        ; get digit back
  1400.     add    al,'0'        ; make printable
  1401.     stosb            ; drop it off
  1402.     ret            ; and return
  1403. outnum    endp
  1404.  
  1405. ; on/off field
  1406. onoff    proc    near
  1407.     call    stmsg        ; copy message
  1408.     call    stval        ; get value cell
  1409.     mov    al,[si]
  1410.     mov    si,offset onmsg
  1411.     mov    cx,2        ; assume 2-byte 'ON' message
  1412.     or    al,al        ; test value
  1413.     jnz    onof1        ; on, have right msg
  1414.     mov    si,offset offmsg
  1415.     mov    cx,3
  1416. onof1:    rep    movsb        ; copy right message in
  1417.     ret            ; and return
  1418. onoff    endp
  1419.  
  1420. ; print first message if false, second if true
  1421. msg2    proc    near
  1422.     call    stval        ; get value cell
  1423.     mov    al,[si]
  1424.     mov    si,[bx].msg    ; assume off
  1425.     or    al,al        ; is it?
  1426.     jz    msg21        ; yes, continue
  1427.     mov    si,[bx].val2    ; else use alternate message
  1428. msg21:    jmp    stms1        ; handle copy and return
  1429. msg2    endp
  1430.  
  1431. ; search a keyword table for a value, print that value
  1432. srchkw    proc    near
  1433.     call    stmsg        ; first print message
  1434.     call    stval
  1435.     mov    al,[si]        ; get value to hunt for
  1436.     mov    ah,0        ; high order is 0
  1437.     mov    bx,[bx].val2    ; this is table address
  1438.     jmp    prttab        ; and look in table.
  1439. srchkw    endp
  1440.  
  1441. ; Print the drive name.
  1442. drnum    proc    near
  1443.     call    stmsg        ; copy message part first
  1444.     call    stval        ; pick up test value address
  1445.     mov    al,[si]        ; this is char to print
  1446.     add    al,'@'        ; Make it printable.
  1447.     stosb
  1448.     mov    byte ptr [di],':'
  1449.     inc    di        ; end with a colon
  1450.     ret            ; and return
  1451. drnum    endp
  1452.  
  1453. ; print 8-bit quoting
  1454. pr8bit    proc    near
  1455.     mov    bl,trans.ebquot    ; get quote char
  1456.     mov    si,offset ebyst    ; assume no 8-bit quoting
  1457.     cmp    bl,'Y'        ; on request only?
  1458.     je    pr8bi1        ; yes, continue
  1459.     mov    si,offset ebvst    ; else variable
  1460. pr8bi1:    call    stms1        ; copy message in
  1461.     cmp    bl,'Y'        ; not doing it?
  1462.     je    pr8bi2        ; no, forget this part
  1463.     mov    [di],bl        ; else drop off char too
  1464.     inc    di
  1465. pr8bi2:    ret            ; and return
  1466. pr8bit    endp
  1467.  
  1468. ; Print the handshake.
  1469. prhnd:    mov si,offset handst    ; copy in initial message
  1470.     call stms1
  1471.     mov si,offset nonmsg    ; assume no handshake
  1472.     mov bx,portval
  1473.     cmp [bx].hndflg,0    ; Is handshaking in effect?
  1474.     jne prh0        ; Yes, print what we're using.
  1475.     jmp stms1        ; no, say so and return
  1476. prh0:    mov al,'¬'        ; Doing handshaking with control char.
  1477.     stosb
  1478.     mov al,[bx].hands
  1479.     add al,40H        ; Make printable.
  1480.     stosb            ; put in buffer
  1481.     ret            ; and return
  1482.  
  1483. ; Print the pad character in AL.
  1484. prpad:    cmp al,127        ; Are they using a delete?
  1485.     jne prpad0
  1486.     mov ah,prstr
  1487.     mov dx,offset delmsg
  1488.     int dos
  1489.     ret
  1490. prpad0:    mov dl,'¬'
  1491.     mov ah,conout
  1492.     push ax
  1493.     int dos
  1494.     pop ax
  1495.     mov dl,al
  1496.     add dl,40H        ; Make printable.
  1497.     int dos
  1498.     ret
  1499.  
  1500. ; Print value from table.  BX/address of table, AL/value of variable.
  1501. prttab:    mov cl,[bx]        ; Number of entries in our table.
  1502.     inc bx            ; Point to the data.
  1503. prtt0:    mov dl,[bx]        ; Length of keyword.
  1504.     inc bx            ; Point to keyword.
  1505.     mov dh,0
  1506.     inc dx            ; Account for "$" in table.
  1507.     mov si,dx        ; Put to index register.
  1508.     cmp ax,[bx+si]        ; Is this the one?
  1509.     je prtt1
  1510.     add bx,dx        ; Go to end of keyword.
  1511.     add bx,2        ; Point to next keyword.
  1512.     dec cl            ; Any more keywords to check?
  1513.     jnz prtt0        ; Yes, go to it.
  1514.     mov bx,offset prterr
  1515. prtt1:    mov si,bx
  1516. prtt2:    jmp stms1        ; copy in message
  1517.     ret            ; and return
  1518.  
  1519. ;    This routine prints out the escape character in readable format.  
  1520.  
  1521. ESCPRT    PROC    NEAR        ; [6 start]
  1522.     mov dl,trans.escchr
  1523.     cmp dl,' '
  1524.     jge escpr2
  1525.     push dx
  1526.     mov ah,prstr
  1527.     mov dx,offset esctl
  1528.     int dos
  1529.     pop dx
  1530.     add dl,040H        ; Make it printable.
  1531. escpr2:    mov ah,conout
  1532.     int dos
  1533.     ret
  1534. ESCPRT    ENDP            ; [6 end]
  1535.  
  1536. ; Print information on the baud rate. [19a]
  1537.  
  1538. BAUDPRT    PROC     NEAR
  1539.     call getbaud        ; read baud rate first
  1540.     mov si,portval
  1541.     mov ax,[si].baud
  1542.     mov dx,offset b48st    ; Assume 4800 baud.
  1543.     cmp ax,B4800
  1544.     jnz bdprt0
  1545.     jmp bdprt2
  1546. bdprt0:    mov dx,offset b12st
  1547.     cmp ax,B1200
  1548.     jnz bdprt1
  1549.     jmp bdprt2
  1550. bdprt1:    mov dx,offset b18st
  1551.     cmp ax,B1800
  1552.     jz bdprt2
  1553.     mov dx,offset b24st
  1554.     cmp ax,B2400
  1555.     jz bdprt2
  1556.     mov dx,offset b96st
  1557.     cmp ax,B9600
  1558.     jz bdprt2
  1559.     mov dx,offset b03st
  1560.     cmp ax,B0300
  1561.     jz bdprt2
  1562.     mov dx,offset b04st
  1563.     cmp ax,B00455
  1564.     jz bdprt2
  1565.     mov dx,offset b05st
  1566.     cmp ax,B0050
  1567.     jz bdprt2
  1568.     mov dx,offset b07st
  1569.     cmp ax,b0075
  1570.     jz bdprt2
  1571.     mov dx,offset b11st
  1572.     cmp ax,B0110
  1573.     jz bdprt2
  1574.     mov dx,offset b13st
  1575.     cmp ax,B01345
  1576.     jz bdprt2
  1577.     mov dx,offset b15st
  1578.     cmp ax,B0150
  1579.     jz bdprt2
  1580.     mov dx,offset b06st
  1581.     cmp ax,B0600
  1582.     je bdprt2
  1583.     mov dx,offset b20st
  1584.     cmp ax,B2000
  1585.     jz bdprt2
  1586.     mov dx,offset b19st
  1587.     cmp ax,B19200
  1588.     jz bdprt2
  1589.     mov dx,offset b38st
  1590.     cmp ax,B38400
  1591.     jz bdprt2
  1592.     mov dx,offset unrec    ; Unrecognized baud rate.
  1593. bdprt2:    mov si,dx        ; this is baud rate
  1594. bdprt3:    jmp stms1        ; go copy it and return
  1595. BAUDPRT    ENDP
  1596.  
  1597. setkey    proc    near        
  1598.     cmp    setktab,0    ; any table?
  1599.     jne    setk0        ; yes, use it
  1600.     mov    dx,offset ermes5
  1601.     jmp    reterr        ; else print error message
  1602. setk0:    mov    dx,offset setktab    ; set key options
  1603.     mov    bx,offset setkhlp
  1604.     mov    ah,cmkey
  1605.     call    comnd
  1606.      jmp    r
  1607.     cmp    bx,-1        ; do we have scan code?
  1608.     jne    setk1        ; yes, skip this part
  1609.  
  1610.     mov    ah,cmtxt
  1611.     mov    bx,offset rdbuf    ; handy buffer
  1612.     mov     dx,offset sk1msg
  1613.     call    comnd
  1614.      jmp    r        ; fail return
  1615.     mov    si,offset rdbuf    ; this is parsed number
  1616.     call    atoi        ; Convert input to real number.
  1617.      jmp    reterr        ; No good.
  1618.     mov    bx,ax        ; put accumulation into bl
  1619. setat3:    cmp    bx,0        ; is scan code 0?
  1620.     jne    setk2        ; no, have scan code, look for def
  1621.  
  1622. setk1:    push    bx        ; save our scan code
  1623.     mov    ah,cmcfm
  1624.     call    comnd
  1625.      jmp     short setkx    ; no good, pop bx and return
  1626.     nop            ; waste a byte
  1627.     pop    bx
  1628. ; scan code is in bl, ask for string part
  1629. setk2:    push    bx
  1630.     mov    dx,offset defpmp
  1631.     call    prompt
  1632.     mov    ah,cmtxt
  1633.     mov    bx,offset rdbuf
  1634.     mov    dx,offset sk2msg
  1635.     call    comnd        ; read the definition
  1636.      jmp    short setkx    ; pop bx and fail return
  1637.      nop
  1638.     mov    cl,ah
  1639.     mov    ch,0        ; set up length of definition
  1640.     pop    ax        ; get scan code back
  1641.     mov    si,offset rdbuf    ; point to definition
  1642.     call    defkey        ; go define the key
  1643.     jmp    rskp        ; and return
  1644. setkx:    pop    bx        ; pop junk off stack
  1645.     ret            ; and return
  1646. setkey    endp
  1647.  
  1648. ; Convert input in buffer pointed to by SI to real number which is returned
  1649. ; in AX.  Return on failure, return skip on success.
  1650. ATOI    PROC    NEAR
  1651.     mov    cl,ah        ; Number of chars of input.
  1652.     mov    ch,0        ; size of string
  1653.     jcxz    atoi4        ; Fail on no input.
  1654.     mov    ax,0        ; init sum
  1655.     mov    bh,0        ; high order of this stays 0.
  1656.     mov    tmp,0        ; No input yet. [27f]
  1657. atoi0:    xchg    al,bl        ; save current sum
  1658.     lodsb            ; grab a byte
  1659.     cmp    al,' '        ; leading space?
  1660.     jne    atoi1        ; no, continue
  1661.     xchg    al,bl        ; put sum back
  1662.     jmp    short atoi2    ; and continue loop
  1663. atoi1:    cmp    al,'9'
  1664.     ja    atoi5        ; out of range, fail
  1665.     cmp    al,'0'
  1666.     jb    atoi5
  1667.     xchg    al,bl        ; put sum back into al
  1668.     mul    ten        ; shift one digit
  1669.     sub    bl,'0'        ; convert to binary
  1670.     add    ax,bx        ; add to sum
  1671.     mov    tmp,1        ; Got some legal input. [27f]
  1672. atoi2:    loop    atoi0        ; loop thru all chars
  1673.     cmp    tmp,0        ; Anything besides spaces? [27f]
  1674.     je    atoi4        ; No so fail. [27f]
  1675.     jmp    rskp
  1676. atoi4:    mov    dx,offset erms23    ; complain and return
  1677.     ret
  1678. atoi5:    mov    dx,offset erms25    ; Input must be numeric
  1679.     ret
  1680. ATOI    ENDP
  1681.  
  1682. ;  addition for capture of raw output
  1683.  
  1684. setcpt    proc    near
  1685.     test    flags.capflg,0FFH
  1686.     jz    setcp1            ; no capture file, keep going
  1687.     mov    dx,offset erms24
  1688.     jmp    reterr
  1689. setcp1:    mov     comand.cmcr,0        ; Filename must be specified.
  1690.     mov    ah,cmifi
  1691.     mov    dx,offset cptfcb
  1692.     mov     bx,offset filhlp
  1693.     call    comnd
  1694.      jmp    r
  1695.     mov    ah,cmcfm
  1696.     call    comnd            ; confirm with carriage return
  1697.      jmp    r
  1698.     mov    ah,delf
  1699.     mov    dx,offset cptfcb
  1700.     int    dos            ; open up file
  1701.     mov    ah,makef
  1702.     mov    dx,offset cptfcb
  1703.     int    dos
  1704.     mov     cptfcb+32,0
  1705.  
  1706.     call    inicpt            ; init capture variables
  1707.     mov    flags.capflg,0FFH    ; know we have capture routine
  1708.     jmp    rskp        ; and return
  1709.  
  1710. setcpt    endp
  1711.  
  1712. ; Jumping to this location is like retskp.  It assumes the instruction
  1713. ;   after the call is a jmp addr.
  1714.  
  1715. RSKP    PROC    NEAR
  1716.     pop bp
  1717.     add bp,3
  1718.     push bp
  1719.         ret
  1720. RSKP    ENDP
  1721.  
  1722. ; Jumping here is the same as a ret.
  1723.  
  1724. R       PROC    NEAR
  1725.         ret
  1726. R       ENDP
  1727.  
  1728. ; routine to print an error message, then retskp
  1729. ; expects message in dx
  1730. reterr    proc    near
  1731.     mov    ah,prstr
  1732.     int    dos
  1733.     jmp    rskp
  1734. reterr    endp
  1735.  
  1736. code    ends 
  1737.     end
  1738.